Private Class MyForm2 : Inherits Form
Public theBrowser As RasterThumbnailBrowser
Public cancelOperation As Boolean
Public buttonCancel As Button
Public buttonBrowse As Button
Public progressBar As ProgressBar
Private Sub buttonBrowse_Click(ByVal sender As Object, ByVal e As EventArgs)
If theBrowser.IsLoadingThumbnails Then
theBrowser.CancelLoadingThumbnails()
End If
theBrowser.Items.Clear()
buttonCancel.Enabled = True
progressBar.Value = 0
cancelOperation = False
Dim folderPath As String = LeadtoolsExamples.Common.ImagesPath.Path
Dim files As String() = New String(1) {folderPath & "\image1.jpx", folderPath}
theBrowser.LoadThumbnails(files, "*.jpg", RasterThumbnailBrowserLoadFlags.Block Or RasterThumbnailBrowserLoadFlags.ExpandMultiPageFile)
End Sub
Private Sub thumbnailBrowser_LoadThumbnail(ByVal sender As Object, ByVal e As RasterThumbnailBrowserLoadThumbnailEventArgs)
If e.Index = 0 Then
progressBar.Minimum = 0
progressBar.Maximum = e.Total - 1
End If
progressBar.Value = e.Index
If cancelOperation Then
e.Cancel = True
End If
End Sub
Private Sub thumbnailBrowser_AddFile(ByVal sender As Object, ByVal e As RasterThumbnailBrowserAddFileEventArgs)
Console.WriteLine("AddFile: {0} Add: {1} Total Pages: {2} Page:{3}", e.FileName, e.Add, e.TotalPages, e.Page)
End Sub
Private Sub thumbnailBrowser_FinishedLoadingThumbnails(ByVal sender As Object, ByVal e As EventArgs)
buttonCancel.Enabled = False
End Sub
Private Sub buttonCancel_Click(ByVal sender As Object, ByVal e As EventArgs)
Me.cancelOperation = True
End Sub
Private Sub CreateErrorThumbnail()
Dim imageSize As Size = theBrowser.ItemImageSize
theBrowser.LoadingThumbnail = Nothing
Dim palette As RasterColor() = New RasterColor() {}
Dim image As RasterImage = New RasterImage(RasterMemoryFlags.Conventional, imageSize.Width, imageSize.Height, 24, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft, palette, IntPtr.Zero, 0)
Dim hdc As IntPtr = image.CreateLeadDC()
Dim g As Graphics = Graphics.FromHdc(hdc)
g.FillRectangle(Brushes.Magenta, 0, 0, imageSize.Width, imageSize.Height)
g.DrawLine(Pens.Red, 0, 0, imageSize.Width, imageSize.Height)
g.DrawLine(Pens.Red, imageSize.Width, 0, 0, imageSize.Height)
g.Dispose()
RasterImage.DeleteLeadDC(hdc)
image.Transparent = True
image.TransparentColor = RasterColor.FromGdiPlusColor(Color.Magenta)
theBrowser.ErrorThumbnail = image
End Sub
Public Sub Cleanup()
RemoveHandler buttonBrowse.Click, AddressOf buttonBrowse_Click
RemoveHandler buttonCancel.Click, AddressOf buttonCancel_Click
RemoveHandler theBrowser.LoadThumbnail, AddressOf thumbnailBrowser_LoadThumbnail
RemoveHandler theBrowser.FinishedLoadingThumbnails, AddressOf thumbnailBrowser_FinishedLoadingThumbnails
End Sub
Public Sub New()
Size = New Size(300, 200)
theBrowser = New RasterThumbnailBrowser()
theBrowser.Codecs = New RasterCodecs()
theBrowser.Dock = DockStyle.Fill
theBrowser.ItemSpacingSize = New Size(10, 10)
theBrowser.ThumbnailSizeFlags = RasterSizeFlags.Bicubic
AddHandler theBrowser.LoadThumbnail, AddressOf thumbnailBrowser_LoadThumbnail
AddHandler theBrowser.FinishedLoadingThumbnails, AddressOf thumbnailBrowser_FinishedLoadingThumbnails
AddHandler theBrowser.AddFile, AddressOf thumbnailBrowser_AddFile
CreateErrorThumbnail()
Dim panel As Panel = New Panel()
panel.Dock = DockStyle.Left
panel.Width = 100
Controls.Add(panel)
panel.BringToFront()
buttonBrowse = New Button()
buttonBrowse.Text = "Browse"
buttonBrowse.Dock = DockStyle.Top
panel.Controls.Add(buttonBrowse)
AddHandler buttonBrowse.Click, AddressOf buttonBrowse_Click
buttonCancel = New Button()
buttonCancel.Text = "Cancel"
buttonBrowse.Dock = DockStyle.Bottom
panel.Controls.Add(buttonCancel)
AddHandler buttonCancel.Click, AddressOf buttonCancel_Click
progressBar = New ProgressBar()
progressBar.Dock = DockStyle.Bottom
Controls.Add(progressBar)
Controls.Add(theBrowser)
theBrowser.BringToFront()
End Sub
Private Sub InitializeComponent()
Me.SuspendLayout()
Me.ClientSize = New System.Drawing.Size(315, 273)
Me.Name = "MyForm"
Me.ResumeLayout(False)
End Sub
End Class
Public Sub RasterThumbnailBrowser_RasterThumbnailBrowser()
RasterCodecs.Startup()
Dim form As MyForm = New MyForm()
form.ShowDialog()
form.Cleanup()
RasterCodecs.Shutdown()
End Sub |